package cn.com.server.start;

import cn.com.common.Constant;
import cn.com.common.URI;
import cn.com.common.utils.IPHelper;
import cn.com.registry.RegistryConfig;
import cn.com.server.export.Export;
import cn.com.server.export.ZhurongExport;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.util.concurrent.CountDownLatch;

/**
 * @author jiaming
 */
public class ServerStart {

    protected static final Logger log = LogManager.getLogger();

    private static final CountDownLatch latch = new CountDownLatch(1);

    public static void main(String[] args) {
        try {
            start();
            log.info("server start!");
            latch.await();
        } catch (Exception e) {
            log.error("server start fail,msg:{}", e.getMessage(), e);
        }
    }

    private static void start() {
        URI uri = new URI();
        uri.setPort(Constant.SERVER_PORT);
        uri.setHost(IPHelper.getHostFirstIp());
        uri.setServiceName(Constant.SERVER_NAME);
        Export export = new ZhurongExport();
        RegistryConfig registryConfig = new RegistryConfig();
        registryConfig.setHost(Constant.ETCD_HOST);
        registryConfig.setPort(Constant.ETCD_PORT);
        registryConfig.setRoot(Constant.SERVER_PATH);
        export.export(registryConfig, uri);
    }

}